<?php
require_once("vcl/vcl.inc.php");
require_once("lib/db_connection.php");
//Includes
use_unit("components4phpfull/jtdivwindow.inc.php");
use_unit("components4phpfull/jtcategorybuttons.inc.php");
use_unit("components4phpfull/jtlabel.inc.php");
use_unit("components4phpfull/jtjavascript.inc.php");
use_unit("components4phpfull/jtpcregex.inc.php");
use_unit("components4phpfull/jtradiobuttonlist.inc.php");
use_unit("comctrls.inc.php");
use_unit("components4phpfull/jtgroupbox.inc.php");
use_unit("components4phpfull/jtsitetheme.inc.php");
use_unit("forms.inc.php");
use_unit("extctrls.inc.php");
use_unit("stdctrls.inc.php");

//Class definition
class CompanyWorkOrders2 extends Page
{
       public $Label4 = null;
       public $Label3 = null;
       public $Label2 = null;
       public $JTGroupBox1 = null;
       public $JTDivInfo = null;
       public $JTGroupBox5 = null;
       public $Label13 = null;
       public $imgInfo = null;
       public $hfError = null;
       public $lblorder = null;
       public $imgBack = null;
       public $imgFinish = null;
       public $chkAutoNumbering = null;
       public $edLastOrderNo = null;
       public $lblLastOrderNo = null;
       public $lblPrefix = null;
       public $edPrefix = null;
       public $lblAutoNumbering = null;
       public $Image3 = null;
       public $JTSiteTheme1 = null;


       function imgInfoJSClick($sender, $params)
       {

       ?>
       //Add your javascript code here
       document.getElementById('JTDivInfo').Show();
       <?php

       }

       function edLastOrderNoJSBlur($sender, $params)
       {

       ?>
       var edLastOrderNo = document.getElementById('edLastOrderNo').value;

       if(edLastOrderNo.length>0)
       {
       regex_pattern = "^[0-9]+$";
       var re = new RegExp(regex_pattern);
       var match = document.getElementById('edLastOrderNo').value.match(re);
       if(match==null)
       {
        document.getElementById('lblorder').innerHTML = "&darr;&nbsp;Pls. enter a number&nbsp;&darr;";
       }

       if(match!=null)
       {
        document.getElementById('lblorder').innerHTML = "";
       }
       }

       <?php

       }

       function imgFinishJSMouseOver($sender, $params)
       {

       ?>
       document.images['imgFinish'].src = 'image/btn_finish2.png';
       <?php

       }

       function imgFinishJSMouseOut($sender, $params)
       {

       ?>
       document.images['imgFinish'].src = 'image/btn_finish.png';
       <?php

       }

       function imgBackJSClick($sender, $params)
       {

       ?>
       window.location.href = "set_vehicle_list.php";

       <?php

       }

       function imgBackJSMouseOut($sender, $params)
       {

       ?>
       document.images['imgBack'].src = 'image/btn_back1.png';
       <?php

       }

       function imgBackJSMouseOver($sender, $params)
       {

       ?>
       document.images['imgBack'].src = 'image/btn_back21.png';
       <?php

       }

       function imgFinishClick($sender, $params)
       {
       $orderno = $this->edLastOrderNo->Text;
       if($orderno!='')
       {
       if(!preg_match("/^[0-9]+$/",$this->edLastOrderNo->Text))
       {
        $this->lblorder->Caption = '&darr;&nbsp;Pls. enter a number&nbsp;&darr;';
        $this->hfError->setValue('1');
       }
       }

       $error = $this->hfError->getValue();
       if($error == '1' || $number != $key)
       {
          $this->hfError->setValue('0');
          return false;
       }
       else if($error == '0')
       {
        if ($this->chkAutoNumbering->Checked==true)
       {
       $chkAutoNumbering ='1';
       }
       else
       {
       $chkAutoNumbering='0';
       }

       /*if ($this->chkFavor->Checked==true)
       {
       $chkFavor='1';
       }
       else
       {
       $chkFavor='0';
       } */

       $result=mysql_query("select * from company_workorders_tbl where company_id='".$_SESSION['company_id']."'");
       $count=mysql_num_rows($result);
       if($count==0)
       {
       mysql_query("insert into company_workorders_tbl (company_id,
       auto_numbering,
       prefix,
       last_order_no)

       Values('".$_SESSION['company_id']."',
       '".$chkAutoNumbering."',
       '".$this->edPrefix->Text."',
       '".$this->edLastOrderNo->Text."')") or die ("insert workorders - " . mysql_error());
       }
       else
       {
       mysql_query("update company_workorders_tbl set
       auto_numbering='".$chkAutoNumbering."',
       prefix='".$this->edPrefix->Text."',
       last_order_no='".$this->edLastOrderNo->Text."'
       where company_id='".$_SESSION['company_id']."'") or die ("update workorders - " . mysql_error());
       }

        $query_up_comp = "UPDATE company_tbl SET flag_settings='1' WHERE company_id='".$_SESSION['company_id']."'";
        mysql_query($query_up_comp) or die("UPDATE SETTINGS ".mysql_error());
        echo "<script type=text/javascript>
        window.opener.document.getElementById('hfSettings').value = 1;
        window.opener.location.reload();
        //alert('You have completed the wizard. If you want to open the wizard again, click on the (show icon) magic wand located on the right most side just above the search bar!');
        window.opener.location.reload();
        //window.close();
        document.location.href='set_wizard_complete.php';
        </script>";
        //redirect('vehicle_list.php?company_id='.$_SESSION['company_id']);



       }



       }

       function cmbDefInvMarkupChange($sender, $params)
       {
       $markup=$this->cmbDefInvMarkup->getItemIndex();
       if ($markup=="Manual")
       {
       $this->edPrice->Enabled=false;
       }

       if ($markup=="Percent")
       {
       $this->edPrice->Enabled=true;
       }

       if ($markup=="Fixed Value")
       {
       $this->edPrice->Enabled=true;
       }


       }

       function rbtnDefInvMarkupJSChange($sender, $params)
       {

       ?>
       //Add your javascript code here
       if(document.CompanyWorkOrders.rbtnDefInvMarkupJSChange[1].checked==true)
       {
       document.CompanyWorkOrders.edPrice.disabled=false;
       }

       <?php

       }


       function CompanyWorkOrders2Create($sender, $params)
       {
       $this->hfError->setValue('0');
       $query = "select * from company_workorders_tbl where company_id='".$_SESSION['company_id']."'";
       $result_show = mysql_query($query)or die("SELECT WORKORDERS- " . mysql_error());
       $row= mysql_fetch_array($result_show);

       if($row['auto_numbering']=='1')
       {
       $this->chkAutoNumbering->Checked=true;
       }
       else
       {
       $this->chkAutoNumbering->Checked=false;
       }

       $this->lblorder->Caption='';

       //$this->cmbType->ItemIndex = $row['type'];
       //$this->rbtnDefInvExpensing->ItemIndex = $row['default_inv_expense'];
       //$this->cmbDefInvMarkup->ItemIndex = $row['default_inv_markup'];
       $this->edPrefix->Text = $row['prefix'];
       $this->edLastOrderNo->Text = $row['last_order_no'];
       //$this->edDefaultCharge->Text = $row['default_charge'];
       //$this->edDays->Text = $row['days'];
       //$this->edExceptFor->Text = $row['except_for'];
       //$this->edPrice->Text = $row['price'];

       //$this->edPrefix->Enabled=false;
       //$this->edLastOrderNo->Enabled=false;
       //$this->edPrice->Enabled=false;
       }

       function chkAutoNumberingJSChange($sender, $params)
       {

       ?>
       //Add your javascript code here
       if(document.CompanyWorkOrders.chkAutoNumbering.checked==true)
       {
       document.CompanyWorkOrders.edPrefix.disabled=false;
       document.CompanyWorkOrders.edLastOrderNo.disabled=false;
       }
       else
       {
       document.CompanyWorkOrders.edPrefix.disabled=true;
       document.CompanyWorkOrders.edLastOrderNo.disabled=true;
       }
       <?php

       }


}

global $application;

global $CompanyWorkOrders2;

//Creates the form
$CompanyWorkOrders2=new CompanyWorkOrders2($application);

//Read from resource file
$CompanyWorkOrders2->loadResource(__FILE__);

//Shows the form
$CompanyWorkOrders2->show();

?>